home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / irit / ctrl-brk.c next >
Encoding:
C/C++ Source or Header  |  1994-12-10  |  2.7 KB  |  58 lines

  1. /*****************************************************************************
  2. * Module to trap ctrl-brk/hardware error and handle them gracefully.         *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 1.1, Mar. 1990   *
  5. *****************************************************************************/
  6.  
  7. #include <signal.h>
  8. #include <stdio.h>
  9. #include "program.h"
  10. #include "inptprsg.h"
  11. #include "ctrl-brk.h"
  12.  
  13. typedef void (* SignalFuncPtr)(int);
  14.  
  15. /*****************************************************************************
  16. * DESCRIPTION:                                                               *
  17. * Routine TrapCtrlC gains control if Control C was typed (DOS level):         *
  18. *                                                                            *
  19. * PARAMETERS:                                                                *
  20. *   Type:     Type of exception.                                             *
  21. *                                                                            *
  22. * RETURN VALUE:                                                              *
  23. *   void                                                                     *
  24. *****************************************************************************/
  25. static void TrapCtrlC(int Type)
  26. {
  27.     printf("\n*** Break ***\n");
  28.     fflush(stdout);
  29.     SetUpCtrlBrk();
  30.  
  31.     FlushToEndOfExpr(FALSE);
  32.     longjmp(GlblLongJumpBuffer, 1);
  33. }
  34.  
  35. /*****************************************************************************
  36. * DESCRIPTION:                                                               M
  37. * Routine SetUpCtrlBrk must be called once by main program, at the beginning.M
  38. *                                                                            *
  39. * PARAMETERS:                                                                M
  40. *   None                                                                     M
  41. *                                                                            *
  42. * RETURN VALUE:                                                              M
  43. *   void                                                                     M
  44. *                                                                            *
  45. * KEYWORDS:                                                                  M
  46. *   SetUpCtrlBrk                                                             M
  47. *****************************************************************************/
  48. void SetUpCtrlBrk(void)
  49. {
  50.     if (getenv("IRIT_NO_SIGNALS") == NULL) {
  51.     signal(SIGINT, (SignalFuncPtr) TrapCtrlC);
  52. #if defined(__UNIX__) || defined(OS2GCC)
  53.     signal(SIGQUIT, (SignalFuncPtr) TrapCtrlC);
  54.     signal(SIGKILL, (SignalFuncPtr) IritExit0);
  55. #endif /* __UNIX__ || OS2GCC */
  56.     }
  57. }
  58.